from cell import *

class Maze(object):
    def __init__(self, width, height):
        self.width = width
        self.height = height
        self.cells = []
        for x in range(width):
            column = []
            self.cells.append(column)
            for y in range(height):
                column.append(Cell())

    def inside(self, x, y):
        if x >= 0 and x < self.width and y >= 0 and y < self.height:
            return True
        else:
            return False

    def open_passage(self, x, y, dir):
        self.cells[x][y].walls[dir].change_to(EMPTY_WALL)
        ox, oy = dir.from_cell(x, y)
        if self.inside(ox, oy):
            self.cells[ox][oy].walls[dir.opposite()].change_to(EMPTY_WALL)

    def can_go(self, x, y, dir):
        if self.cells[x][y].can_go(dir):
            nx, ny = dir.from_cell(x, y)
            if nx >= 0 and nx < self.width and ny >= 0 and ny < self.height:
                return True
        else:
            return False
